package cn.usts.edu.Reflection03;

/**
 * 一个类在内存中只有一个class对象唯一的
 *  反射的原理:
 *      所有的类都有一个公共的祖宗类,都是Class的子类,所以根据他的父类可以倒退找到他的子类
 *      从而调用到子类中到方法和属性
 * */

public class ReflectionDemo {


    public static void main(String[] args) throws ClassNotFoundException {
        Class c1 = Class.forName("cn.usts.edu.Reflection03.User");
        System.out.println(c1);
        Class c2 = Class.forName("cn.usts.edu.Reflection03.User");
        Class c3 = Class.forName("cn.usts.edu.Reflection03.User");
        Class c4 = Class.forName("cn.usts.edu.Reflection03.User");
        Class c5 = Class.forName("cn.usts.edu.Reflection03.User");

        // 一个类在内存中只有一个class对象
        // 一个类被加载后,类的整个结构都会被封装在class对象中,所以他们的哈希值是一样的
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());
        System.out.println(c4.hashCode());
        System.out.println(c5.hashCode());





    }

}



// 实体类,pojo,entity
class User{
    private int age;
    private int id;
    private String name;

    public User(int age, int id, String name) {
        this.age = age;
        this.id = id;
        this.name = name;
    }

    public User() {
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "age=" + age +
                ", id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
